﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>增加、删除、修改节点</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link href="../demo.css" rel="stylesheet" type="text/css" />

    
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    
    

</head>
<body>
    <h1>增加、删除、修改节点</h1>      

    <input type="button" value="插入节点(前)" onclick="onAddBefore()"/>
    <input type="button" value="插入节点(后)" onclick="onAddAfter()"/>
    <input type="button" value="插入节点(子节点)" onclick="onAddNode()"/>
    <input type="button" value="保存" onclick="saveData()" style="margin-left:30px;font-weight:bold;"/>
    <br />
    <input type="button" value="编辑节点" onclick="onEditNode()"/>
    <input type="button" value="删除节点" onclick="onRemoveNode()"/>
    
    
    <ul id="tree1" class="mini-tree" url="../data/listTree.txt" style="width:200px;padding:5px;" 
        showTreeIcon="true" textField="text" idField="id" parentField="pid" resultAsTree="false"  
        allowDrag="true" allowDrop="true" 
        >
    </ul>
   
        
    <script type="text/javascript">

        function onAddBefore(e) {
            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();

            var newNode = {};
            tree.addNode(newNode, "before", node);
        }
        function onAddAfter(e) {
            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();

            var newNode = {};
            tree.addNode(newNode, "after", node);
        }
        function onAddNode(e) {
            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();

            var newNode = {};
            tree.addNode(newNode, "add", node);
        }
        function onEditNode(e) {
            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();
            
            tree.beginEdit(node);
        }
        function onRemoveNode(e) {

            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();

            if (node) {
                if (confirm("确定删除选中节点?")) {
                    tree.removeNode(node);
                }
            }
        }
        function onMoveNode(e) {
            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();

            alert("moveNode");
        }
        function saveData() {
            var tree = mini.get("tree1");
            var data = tree.getData();
            var json = mini.encode(data);

            var msgid = mini.loading("数据保存中，请稍后......", "保存数据");
            $.ajax({
                url: "../data/TreeService.jsp?method=SaveTree",
                data: { data: json },
                type: "post",
                success: function (text) {
                    mini.hideMessageBox(msgid);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
        }
    </script>

    <div class="description">
        <h3>Description</h3>
        <p>            
        </p>
    </div>
</body>
</html>